home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 2 code / Using C++ objects / TestPtrObject.cp < prev    next >
Encoding:
Text File  |  1990-08-21  |  1.7 KB  |  85 lines  |  [TEXT/MPS ]

  1. // TestPtrObject.cp
  2. #include <Types.h>
  3. #include <QuickDraw.h>
  4. #include <Fonts.h>
  5. #include <SegLoad.h>
  6. #include <Events.h>
  7. #include <Windows.h>
  8. #include <Menus.h>
  9. #include <TextEdit.h>
  10. #include <Dialogs.h>
  11. #include <Memory.h>
  12. #include <OSUtils.h>
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <stddef.h>
  16.  
  17. #include "PtrObject.h"
  18.  
  19. // A small class that contains some data and a constructor,
  20. // but spends all of its time on street corners cadging
  21. // cigarettes instead of doing useful work.
  22. class TLout : public PtrObject {
  23. public:
  24.     // Our constructor.
  25.                     TLout() { DoCadge(); };
  26.     // A rude member function.
  27.     virtual void    DoCadge();
  28. private:
  29.     char            fArray[256];
  30. };
  31.  
  32. void TLout::DoCadge()
  33. {
  34.     strcpy(fArray,"Hey buddy, spare a cig?");
  35. };
  36.  
  37. void InitToolbox();        // Forward declaration.
  38.  
  39. void main()
  40. {
  41.     // Initialize Mac Toolbox (ho hum).
  42.     InitToolbox();
  43.  
  44.     // We need this much space to store the objects
  45.     // we’re going to initialize - in this case, 16KBytes.
  46.     const size_t kDefaultHeapSize = 0x4000;
  47.  
  48.     // Create a heap for PtrObjects to live in.
  49.     OSErr heapErr = PtrObject::AllocHeap(kDefaultHeapSize);
  50.  
  51.     // If we got an error, quit - this isn’t a real
  52.     // application, so we don’t need error handling, right?
  53.     if (heapErr != noErr)
  54.      ExitToShell();
  55.  
  56.     // Create an object - will go in separate heap automatically.
  57.     TLout* aLout = new TLout;
  58.  
  59.     // Do that voodoo that TLouts do…
  60.     if (aLout != nil)
  61.      {
  62.         aLout->DoCadge();
  63.         // Delete our object now that we have finished with it.
  64.         delete aLout;
  65.      }
  66.     
  67.     // Dispose of the heap.
  68.     PtrObject::DisposeHeap();
  69.     ExitToShell();
  70. }
  71.  
  72. void InitToolbox()
  73. {
  74.     // Standard Macintosh initialization.
  75.     InitGraf((Ptr) &qd.thePort);
  76.     InitFonts();
  77.     InitWindows();
  78.     InitMenus();
  79.     TEInit();
  80.     InitDialogs(nil);
  81.     InitCursor();
  82.     MaxApplZone();
  83. }
  84.  
  85.